import time
from urllib.parse import urljoin

import ddddocr
from DrissionPage import ChromiumPage

page = ChromiumPage()

url = "http://127.0.0.1:8000/captcha/"
page.get(url)

img_url = page.ele('xpath://img[@class="captcha"]').attr('src')
full_img_url = urljoin(url, img_url)
time.sleep(3)

image_content = page.session.get(full_img_url).content

ocr = ddddocr.DdddOcr()
result = ocr.classification(image_content)
print(result)

page.ele('xpath://input[@name="captcha_1"]').input(result)
time.sleep(3)

page.ele('xpath://input[@type="submit"]').click()
